﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.Web.Services.Protocols;

namespace EntLibContrib.Query.Commands
{
	/// <summary>
	/// Simple class to hold the components of a reflected web service command
	/// </summary>
	/// <remarks>
	/// This is only required for use with a legacy web service client proxy.
	/// Even if the service itself is an older web service, rather than a WCF service,
	/// the client proxy may still be generated as a Wcf service in which case you need to
	/// use the WcfServiceQuery instead.
	/// </remarks>
	public class WebServiceCommand : ServiceCommand
	{
		#region Properties
		/// <summary>
		/// Gets an instance of the service object.
		/// </summary>
		/// <value>The service object.</value>
		/// <remarks>override this property if your service constructor takes parameters</remarks>
		public override object ServiceObject
		{
			get
			{
				WebClientProtocol webServiceObject = base.ServiceObject as WebClientProtocol;
				if (webServiceObject != null)
					if (!String.IsNullOrEmpty(Address))
						webServiceObject.Url = Address;

				return webServiceObject;
			}
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceCommand"/> class.
		/// </summary>
		public WebServiceCommand()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="WebServiceCommand"/> class.
		/// </summary>
		/// <param name="address">The address.</param>
		/// <param name="service">The service.</param>
		/// <param name="method">The method.</param>
		/// <param name="parameters">The parameters.</param>
		public WebServiceCommand(string address, string service, string method, ParameterDictionary parameters)
			: base(address, service, method, parameters)
		{
		}
		#endregion
	}
}
